package org.pointex.util;

import java.util.List;

/**
 * ��װ��ҳ��Ϣ
 * 
 * @author Szqiu
 *
 * @param <T>
 */
public class DoPage<T> {

	// �ܼ�¼��
	private Integer totalRecords = 0;
	// ��ҳ��
	private Integer totalPage = 1;
	// ÿҳ��ʾ��¼��
	private Integer pageSize = 5;

	// ��һҳ
	private Integer priverousPage = 1;
	// ��ǰҳ
	private Integer currentPage = 1;
	// ��һҳ
	private Integer nextPage = 1;

	// ��ҳ
	private Integer TopPage = 1;
	// βҳ
	private Integer BottomPage = 1;

	// ��ǰҳ������¼��
	private Integer firstRecord = 0;
	// ��ǰҳ����¼��
	private Integer lastRecord = 0;

	// �洢�����
	private List<T> list;

	/**
	 * ��ȡ�����
	 * 
	 * @return
	 */
	public List<T> getList() {
		return list;
	}

	/**
	 * �洢�����
	 * 
	 * @param list
	 */
	public void setList(List<T> list) {
		this.list = list;
	}

	/**
	 * ��ȡ�ܼ�¼��
	 * 
	 * @return
	 */
	public Integer getTotalRecords() {
		return totalRecords;
	}

	/**
	 * �����ܼ�¼��
	 * 
	 * @param totalRecords
	 */
	public void setTotalRecords(Integer totalRecords) {
		this.totalRecords = totalRecords;
	}

	/**
	 * ��ȡ��ҳ��
	 * 
	 * @return
	 */
	public Integer getTotalPage() {
		// �жϵ�ǰ�ܼ�¼���Ƿ�С�ڵ�ǰҳ����ʾ���� ���ڣ��ܼ�¼/ÿҳ��ʾ���� С�ڣ� 1��
		if (this.pageSize < this.totalRecords)
			return this.totalRecords / this.pageSize + 1;
		else
			return 1;
	}

	/**
	 * ��ȡ��ǰҳ��ʾ��¼��
	 * 
	 * @return
	 */
	public Integer getPageSize() {
		return pageSize;
	}

	/**
	 * ���õ�ǰҳ��ʾ��¼��
	 * 
	 * @param pageSize
	 */
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * ��ȡ��һҳ
	 * 
	 * @return
	 */
	public Integer getPriverousPage() {
		// ������һҳ���жϵ�ǰҳ�Ƿ�С��1�����ڣ���ǰҳ-1��С�ڣ�1
		if (this.currentPage > 1)
			return this.currentPage - 1;
		else
			return 1;
	}

	/**
	 * ��ȡ��ǰҳ
	 * 
	 * @return
	 */
	public Integer getCurrentPage() {
		return currentPage;
	}

	/**
	 * ���õ�ǰҳ
	 * 
	 * @param currentPage
	 */
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * ��ȡ��һҳ
	 * 
	 * @return
	 */
	public Integer getNextPage() {
		// ������һҳ���жϵ�ǰҳ�Ƿ�С����ҳ���� ���ڣ���ǰҳ+1�� С�� �� 1��
		if (this.currentPage < getBottomPage())
			return this.currentPage + 1;
		else
			return 0;
	}

	/**
	 * ��ȡ��ҳ
	 * 
	 * @return
	 */
	public Integer getTopPage() {
		return 1;
	}

	/**
	 * ��ȡβҳ
	 * 
	 * @return
	 */
	public Integer getBottomPage() {
		if (this.totalRecords % this.pageSize > 0)
			return this.totalRecords / this.pageSize + 1;
		else
			return this.totalRecords / this.pageSize;
	}

	/**
	 * ��ǰҳ������¼
	 * 
	 * @return
	 */
	public Integer getFirstRecord() {
		if(this.currentPage > 1)
			return this.pageSize * (this.currentPage - 1);
		else 	
			return 0;
	}

	/**
	 * ��ǰҳ����¼
	 * 
	 * @return
	 */
	public Integer getLastRecord() {
		
		return (this.pageSize) * this.currentPage - 1;
	}

}
